<?php

/**
 * Created by PhpStorm.
 * User: tianrui
 * Date: 2018/1/29 0029
 * Time: 9:51
 */
class Department_model extends CI_Model
{
    /**
     * User_model constructor.
     * 构造函数，加载数据库配置文件
     */
    public function __construct()
    {
        $this->load->database();
    }
    /**
     * 查询全部角色
     * @return mixed
     */
    public function getAll()
    {
        $query = $this->db->get('department');
        return $query->result_array();
    }

    /**
     * 添加角色
     * @param $data
     */
    public function addDepartment($data)
    {
        $this->db->insert('department', $data);
    }

    /**
     * 删除角色
     * @param $id
     */
    public function deleteDepartment($id)
    {
        $this->db->delete('department', array('id' => $id));
    }

    /**
     * 更新角色
     * @param $data
     */
    public function updateDepartment($data)
    {
        $this->db->update('department', $data, array('id' => $data['id']));
    }

    /**
     * 按id查询角色
     * @param $id
     * @return mixed
     */
    public function getDepartmentById($id)
    {
        //$query = $this->db->get_where('department', array('id' => $id));
        $query = $this->db->get_where('department', array('id' => $id));
        return $query->row_array();
    }

    /**
     * 模糊查询
     * @param $role_search
     * @return mixed

    public function getSearch($department_search){
     * $this->db->like('role_name',$role_search,'both');
     * $query = $this->db->get('department');
     * return $query->result_array();
     * }  */
}